package br.util;


	import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
	  
	/** 
	 * 
	 * @author fabio.guimaraes 
	 */  
	public class LoginFiltro implements Filter {  
	  
	    // The filter configuration object we are associated with.  If  
	    // this value is null, this filter instance is not currently  
	    // configured.   
	    
	  
	    public LoginFiltro() {  
	    }   
	      
	    public void doFilter(ServletRequest request, ServletResponse response,  
	                         FilterChain chain)  
	    throws IOException, ServletException {  
	  
	        HttpServletRequest req = (HttpServletRequest) request;  
	        HttpServletResponse resp = (HttpServletResponse) response;  
	        String url = req.getRequestURL().toString();  
	        Object logged = req.getSession().getAttribute("usuariologado");  
	        	        	        
	    if(logged == null || ((String)logged).toString() == "" ){        	
	        	if(!url.contains("login")) {  
	                resp.sendRedirect("../../../login.jsf");  
	                return;
	            }  
	    }  
	      
	    try {  
	        chain.doFilter(request, response);  
	    }catch(Throwable t) {
	        t.printStackTrace();  
	    	}  
	  
	    }    
	    public void destroy() {   
	    }  
	  
	    public void init(FilterConfig filterConfig) {    
	    }
	    
	    public Boolean VerificaPermissao(String login, String url){
	    
	    	return false;
	    }
	}  

